/**
 * 
 */
package sailing.dao.impl;

import org.apache.commons.dbutils.QueryRunner;

import cjlite.daosupport.BaseDao;
import cjlite.daosupport.SqlHelper;
import cjlite.logger.Logger;
import sailing.dao.CashAccountDao;
import sailing.entity.CashAccount;

/**
 * @author kevin
 * 
 */
public class CashAccountDaoImpl extends BaseDao implements CashAccountDao {

	private static Logger logger = Logger.thisClass();

	@Override
	public boolean save(CashAccount ca) {
		return this.persist(ca);
	}

	private SqlHelper getLastCashAccountSql = SqlHelper.selectSql("CashAccount").where(" modifyTime = select max(modifyTime) from  CashAccount");

	@Override
	public CashAccount getLatestCashAccount() {
		logger.entry();
		try {
			QueryRunner qr = this.getQueryRunner();
			CashAccount ca = qr.query(getLastCashAccountSql.toSqlString(), this.getBeanHandler(CashAccount.class));
			return ca;
		} catch (Exception e) {
			logger.error("error on select '{0}' entity ~~", e, CashAccount.class.getName());
		}
		logger.exit();
		return null;
	}

}
